
public class Vector implements Structura 
{
	protected int[] vector;
	private static int poz;//poz. curenta in vector
	private static int lungimeMaxima;//lung. max. a vect.
	public Vector()
	{
		poz=0;
		lungimeMaxima=10;
		vector=new int[10];
	}//constructor de initializare 
	public Vector(int dimensiune)
	{
		poz=0;
		lungimeMaxima=dimensiune;
		vector=new int[dimensiune];
	}
	private int[] getVector()//returneaza vectorul
	{
		return this.vector;
	}
	private void setVector(int[] v)//modifica vectorul
	{
		int n=v.length;
	    for(int i=0;i<n;i++)
	    {
	    	this.vector[i]=v[i];
	    }
	    
	}
	public void adauga(int elem)//pt. adaugarea unui element dat ca parametru in vector;
	{
		if(poz<lungimeMaxima)
		{
		vector[poz]=elem;
		poz=poz+1;
		}
		else
		{
			System.err.println("[Error]The vector is full, no more elements can be accepted "+elem);
		}
	}
	public void sterge(int elem)//pt. eliminarea unui element dat ca parametru din vector;
	{
		int i=0;
		int[] aux=new int[lungimeMaxima];
		int pozAux=0;
		int nrAparitii=0;//se contorizeaza numarul de aparitii pentru a restabili poz corect
		while(i<poz)
		{
			if(this.vector[i]!=elem)
			{
			  	aux[pozAux]=this.vector[i];//am folosit un vect. aux. pt. eliminarea elem.
			  	pozAux++;
			}
			else
			{
				nrAparitii++;
			}
			i++;
		}
		this.setVector(aux);
		poz=poz-nrAparitii;
	}
	
	public int elementLaIndice(int indice)//returneaza valoarea elementului cu un anumit indice dat
	{
		if((indice>=0)&&(indice<lungimeMaxima)&&(indice<=poz))
		{
			return this.vector[indice];
		}
	    else
	    {
		  System.err.println("[Error] The index "+indice+" is invalid.");
		  return -1;
	    }
	}
	public void afiseaza()//afiseaza vectorul
	{
		if(poz>0)
		{
		for(int i=0;i<poz;i++)
		{
			System.out.println("vector["+i+"]="+this.vector[i]);
		}
		}
		else
		{
			System.out.println("There is no element in the vector");
		}
	}

}
